import { repoList, tagList, downloadLocal,} from './utils/git';
import ora from 'ora';
import inquirer from 'inquirer';

let install = async () => {
    let loading = ora('fetching template ......');
    loading.start()
    let list = await repoList();
    loading.succeed();
    list = list.map(({name}) => name);
    let answer = await inquirer.prompt([{
        type: 'list',
        name: 'project',
        choices: list,
        questions: 'pleace choice template'
    }]);
    let project = answer.project;
    loading = origin('fetching tag ......');
    loading.start();
    list = await tagList(project);
    loading.succeed();
    list = list.map(({name}) => name);
    let tag=answer.tag;
    loading=ora('download project ......');
    loading.start();
    await downloadLocal(project,tag);
    loading.succeed();
}

export default install;
